#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: data_sync_source_node.py 
@version:
@time: 2022/03/23 
"""
from TapClientCore.T04_logic.Dag02.node.node_base import NodeBase


class DataSyncSourceNode(NodeBase):
    node = None

    def __init__(self, datasource_name):
        self.generate_node(datasource_name)

    def generate_node(self, datasource_name):
        """
        {
            name: '',
            type: '',
            tableName: '',
            totalReadMethod: 'fullRead',
            increasePoll: 'fullRead',
            increaseSyncInterval: 500,
            increaseRedSize: 100
        }
        """
        from TapClientCore.T05_TM_feature.v2.TMF01_datasource.tmf_http import TMFHttp
        from TapClientCore.T03_api_body_templates.v2_api_body import TASK_CREATE_DATA_SYNC_DAG_NODE_SOURCE
        TMF = TMFHttp()
        response = TMF.get_data_source_by_name(datasource_name)
        node = {
            'id': self.newId,
            'attrs': {
                'position': [
                    -1000,
                    200
                ],
                'connectionName': datasource_name,
                'connectionType': response.get('connection_type'),
                'pdkHash': response.get('pdkHash'),
                'pdkType': 'pdk',
            },
            'databaseType': response.get('database_type'),
            'connectionId': response.get('id'),
        }
        tmp = TASK_CREATE_DATA_SYNC_DAG_NODE_SOURCE.copy()
        tmp.update(node)
        self.node = tmp


class DataSyncSourceNode2(DataSyncSourceNode):
    def __init__(self, datasource_name):
        super(DataSyncSourceNode2, self).__init__(datasource_name)
        self.node['attrs']['position'] = [
            -1000,
            0
        ]


class DataSyncSourceNode3(DataSyncSourceNode):
    def __init__(self, datasource_name):
        super(DataSyncSourceNode3, self).__init__(datasource_name)
        self.node['attrs']['position'] = [
            -1000,
            -200
        ]


if __name__ == '__main__':
    T = DataSyncSourceNode('AUTO_TIDB_SOURCE')
    print(T.node)
